﻿using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using OpenAdmin.Application.Services;
using OpenAdmin.Application.Services.Dtos;

namespace OpenAdmin.HttpApi.Controllers;

/// <summary>
/// 接口相关Api
/// </summary>
[ApiExplorerSettings(GroupName = "Application")]
public class MenuController : ApiControllerBase
{
    private readonly IMenuService _menuServices;
    /// <summary>
    /// 构造函数
    /// </summary>
    public MenuController(IMenuService menuServices)
    {
        _menuServices = menuServices;
    }

    /// <summary>
    /// 获取全部菜单列表
    /// </summary>
    /// <returns></returns>
    [HttpGet, ProducesResponseType(typeof(List<MenusResponseDto>), 200)]
    public async Task<IActionResult> GetMenus()
    {
        return Ok(await _menuServices.GetMenus());
    }

    /// <summary>
    /// 添加菜单
    /// </summary>
    /// <param name="requestDto"></param>
    /// <returns></returns>
    [HttpPost, UnitOfWork]
    public async Task<IActionResult> AddMenu(AddMenuRequestDto requestDto)
    {
        await _menuServices.AddMenu(requestDto);

        return Ok();
    }

    /// <summary>
    /// 更新菜单
    /// </summary>
    /// <param name="requestDto"></param>
    [HttpPost]
    public async Task<IActionResult> EditMenu(EditMenuRequestDto requestDto)
    {
        await _menuServices.EditMenu(requestDto);

        return Ok();
    }

    /// <summary>
    /// 删除菜单
    /// </summary>
    /// <param name="id"></param>
    [HttpPost]
    public async Task<IActionResult> DeleteMenu(int id)
    {
        await _menuServices.DeleteMenu(id);

        return Ok();
    }
}
